/*
Please contact Nate Kelly at Nathan.J.Kelly@gmail.com if you find errors or omissions.
Note: Change paths to accurately identify location of replication files on your machine.
graphmfx.ado, which is included as part of the replication files must be installed
in your personal ado directory in order to reproduce interaction charts. Comment
these out if you do not want to reproduce these charts or install the graphmfx.ado
file.
*/
use "replication_dataset.dta", clear

set more off

*Table 1 models

regress d.feddereg d.dempres d.demsen d.demhouse
estimates store model1

regress d.feddereg d.unified
estimates store model2

regress d.top_p01 l.top_p01 d.feddereg l.feddereg d.topmarg l.topmarg d.union l.union d.dow_2005 l.dow_2005 d.openness l.openness year
estimates store model3

textable *, fmt(%9.2f)


*Table 2 models

local i=1982

while `i'<=1982 {

capture drop post`i'
gen post`i'=0
replace post`i'=1 if year>=`i'
label var post`i' "Post-`i'"

capture drop d_dempresXpost`i' 
capture drop d_demsenXpost`i' 
//capture drop d_demhouseXpost`i'
capture drop d_unifiedXpost`i'

gen d_dempresXpost`i' = d.dempres*post`i'
label var d_dempresXpost`i' "$\Delta$ Dem President\$_t$*Post-`i'\$_t$"
gen d_demsenXpost`i' = d.demsen*post`i'
label var d_demsenXpost`i' "$\Delta$ Dem Senate\$_t$*Post-`i'\$_t$"
gen d_unifiedXpost`i' = d.unified*post`i'
label var d_unifiedXpost`i' "$\Delta$ Unified Democrat\$_t$*Post-`i'\$_t$"


local i = `i' + 1
}


estimates drop _all
regress d.feddereg d.dempres d.demsen d_dempresXpost1982 d_demsenXpost1982 post1982 
estimates store model1

graphmfx d.dempres, condition1(post1982) interaction1(d_dempresXpost1982)
twoway (scatter marg post1982, mcolor(black) msymbol(circle)) (rcap upper lower post1982, ///
lcolor(black) msize(medium)), ytitle("Marginal Effect for Democratic President" "(90% Confidence Interval, two-tailed)") ///
xtitle("") xscale(range(-.50 1.5)) xlabel(0 "Pre-1982" 1 "Post-1982") legend(off)

graphmfx d.demsen, condition1(post1982) interaction1(d_demsenXpost1982)
twoway (scatter marg post1982, mcolor(black) msymbol(circle)) (rcap upper lower post1982, ///
lcolor(black) msize(medium)), ytitle("Marginal Effect for Democratic Senate" "(90% Confidence Interval, two-tailed)") ///
xtitle("") xscale(range(-.50 1.5)) xlabel(0 "Pre-1982" 1 "Post-1982") legend(off)

regress d.feddereg d.unified d_unifiedXpost1982 post1982

*Loans per capita
capture drop d_loanspercap
gen d_loanspercap=d.loanspercap
label var d_loanspercap "$\Delta$ Total Loans Per Capita\$_t$"
capture drop d_demsenXd_loanspercap
gen d_demsenXd_loanspercap=d.demsen*d.loanspercap
label var d_demsenXd_loanspercap "$\Delta$ Democratic Senate\$_t$*\$\Delta$ Loans\$_t$"
regress d.feddereg d.demsen d_demsenXd_loanspercap d_loans
estimates store loans

graphmfx d.demsen, condition1(d_loanspercap) interaction1(d_demsenXd_loanspercap)
capture drop where
capture drop pipe
gen where=0
gen pipe="|"
twoway (line marg d_loanspercap, sort clcolor(black)) ///
(line upper d_loanspercap,  sort clpattern(dash) clcolor(black)) ///
(line lower d_loanspercap, sort clpattern(dash)  clcolor(black)) ///
(scatter where d_loanspercap, ms(none) mlabel(pipe) mlabcolor(black) mlabpos(0)), ///
legend(off) yline(0) ytitle("Marginal Effect for Democratic Senate" "(90% Confidence Interval, two-tailed)") ///
xtitle("Value of {&Delta} Total Loans Per Capita")

*Campaign finance

capture drop d_relativefinance
gen d_relativefinance=d.relativefinance
label var d_relativefinance "$\Delta$ Finance Contributions\$_t$"
capture drop d_demsenXd_relativefinance
gen d_demsenXd_relativefinance=d.demsen*d.relativefinance
label var d_demsenXd_relativefinance "$\Delta$ Dem Senate\$_t$*\$\Delta$ Finance Contributions\$_t$"
regress d.feddereg d.demsen d_demsenXd_relativefinance d_relativefinance
estimates store money

graphmfx d.demsen, interaction1(d_demsenXd_relativefinance) condition1(d_relativefinance) 
capture drop where
capture drop pipe
gen where=0
gen pipe="|"
twoway (line marg d_relativefinance, sort clcolor(black)) ///
(line upper d_relativefinance,  sort clpattern(dash) clcolor(black)) ///
(line lower d_relativefinance, sort clpattern(dash)  clcolor(black)) ///
(scatter where d_relativefinance, ms(none) mlabel(pipe) mlabcolor(black) mlabpos(0)), ///
legend(off) yline(0) ytitle("Marginal Effect for Democratic Senate" "(90% Confidence Interval, two-tailed)") ///
xtitle("Value of {&Delta} Finance Sector Contributions")

*Unions

capture drop d_union
gen d_union=d.union
label var d_union "$\Delta$ Union Membership\$_t$"
capture drop d_demsenXd_union
gen d_demsenXd_union=d.demsen*d.union
label var d_demsenXd_union "$\Delta$ Dem Senate\$_t$*\$\Delta$ Union Membership\$_t$"
regress d.feddereg d.demsen d_demsenXd_union d_union
estimates store unions

graphmfx d.demsen, interaction1(d_demsenXd_union) condition1(d_union)
capture drop where
capture drop pipe
gen where=0
gen pipe="|"
twoway (line marg d_union, sort clcolor(black)) ///
(line upper d_union,  sort clpattern(dash) clcolor(black)) ///
(line lower d_union, sort clpattern(dash)  clcolor(black)) ///
(scatter where d_union, ms(none) mlabel(pipe) mlabcolor(black) mlabpos(0)), ///
legend(off) yline(0) ytitle("Marginal Effect for Democratic Senate" "(90% Confidence Interval, two-tailed)") ///
xtitle("Value of {&Delta} Union Strength")

*Trade openness

capture drop d_openness
gen d_openness=d.openness
label var d_openness "$\Delta$ Trade Openness\$_t$"
capture drop d_demsenXd_openness
gen d_demsenXd_openness=d.demsen*d.openness
label var d_demsenXd_openness "$\Delta$ Dem Senate\$_t$*\$\Delta$ Trade Openness\$_t$"
regress d.feddereg d.demsen d_demsenXd_openness d_openness
estimates store openness

graphmfx d.demsen, interaction1(d_demsenXd_openness) condition1(d_openness) 
capture drop where
capture drop pipe
gen where=0
gen pipe="|"
twoway (line marg d_openness, sort clcolor(black)) ///
(line upper d_openness,  sort clpattern(dash) clcolor(black)) ///
(line lower d_openness, sort clpattern(dash)  clcolor(black)) ///
(scatter where d_openness, ms(none) mlabel(pipe) mlabcolor(black) mlabpos(0)), ///
legend(off) yline(0) ytitle("Marginal Effect for Democratic Senate" "(90% Confidence Interval, two-tailed)") ///
xtitle("Value of {&Delta} Trade Openness")

textable *, fmt(%9.2f)

estimates drop _all
drop marg-pipe


*******************************************************************************************************************




*SI Models

*Unit root tests

local varsused "feddereg dempres demsen demhouse unified loanspercap relativefinance union openness top_p01 dow_2005 topmarg capgtax"

foreach var of local varsused {
dfuller `var'
kpss `var'
}

*Descriptive stats for all variables

foreach var of local varsused {
sum `var' if year>=1914 & year<=2010
}


*Chart for deregulation and top income shares

twoway (tsline feddereg) if year>=1914 & year<=2010, ylabel(, angle(forty_five)) ttitle(Year) tlabel(1914(8)2010, angle(forty_five))
graph save "C:\Users\Nathan Kelly\OneDrive\Nathan Kelly\Academic Work\Research Projects\Income Inequality\National\Papers\Financial Deregulation Keller\feddereg.gph", replace
graph export "C:\Users\Nathan Kelly\OneDrive\Nathan Kelly\Academic Work\Research Projects\Income Inequality\National\Papers\Financial Deregulation Keller\feddereg.pdf", as(pdf)  replace

twoway (tsline top_p01) if year>=1914 & year<=2010, ylabel(, angle(forty_five)) ttitle(Year) tlabel(1914(8)2010, angle(forty_five))
graph save "C:\Users\Nathan Kelly\OneDrive\Nathan Kelly\Academic Work\Research Projects\Income Inequality\National\Papers\Financial Deregulation Keller\top_p01.gph", replace
graph export "C:\Users\Nathan Kelly\OneDrive\Nathan Kelly\Academic Work\Research Projects\Income Inequality\National\Papers\Financial Deregulation Keller\top_p01.pdf", as(pdf)  replace


*Relax the endogeneity assumption and also conduct Granger causality tests.

var top_p01 feddereg union dow_2005 openness topmarg, lags(1/4)
irf create irfs1, set(irfs1) replace
irf graph irf, impulse(top_p01 feddereg) response(top_p01 feddereg) 
vargranger

*Chow Tests determining whether there is a regime change on effect of partisan variables

local i=1975

while `i'<=1986 {

capture drop post`i'
gen post`i'=0
replace post`i'=1 if year>=`i'
label var post`i' "Post-`i'"

capture drop d_dempresXpost`i' 
capture drop d_demsenXpost`i' 
capture drop d_demhouseXpost`i'
capture drop d_unifiedXpost`i'

gen d_dempresXpost`i' = d.dempres*post`i'
label var d_dempresXpost`i' "$\Delta$ Dem President\$_t$*Post-`i'\$_t$"
gen d_demsenXpost`i' = d.demsen*post`i'
label var d_demsenXpost`i' "$\Delta$ Dem Senate\$_t$*Post-`i'\$_t$"
gen d_demhouseXpost`i' = d.demhouse*post`i'
label var d_demhouseXpost`i' "$\Delta$ Dem House\$_t$*Post-`i'\$_t$"
gen d_unifiedXpost`i' = d.unified*post`i'
label var d_unifiedXpost`i' "$\Delta$ Unified Democrat\$_t$*Post-`i'\$_t$"

regress d.feddereg d.dempres d.demsen d_dempresXpost`i' d_demsenXpost`i' post`i'
test post`i' d_dempresXpost`i' d_demsenXpost`i'

local i = `i' + 1
}



* Alternative Specifications


estimates drop _all

regress d.top_p01 l.top_p01 d.feddereg l.feddereg d.union l.union d.dow_2005 l.dow_2005 d.openness l.openness d.capgtax l.capgtax d.topmarg l.topmarg
estimates store model1

gen year2=year^2
gen year3=year^3
regress d.top_p01 l.top_p01 d.feddereg l.feddereg d.union l.union d.dow_2005 l.dow_2005 d.openness l.openness year year2 year3
estimates store model2

textable *, fmt(%9.2f)
estimates drop _all
drop d_loanspercap-year3
erase irfs1.irf


*Micro level analysis

use "replication_micro.dta", clear

estimates drop _all

probit gs_repeal_yea finance_10k democrat financeXdem
estimates store gs2

graphmfx democrat, interaction1(financeXdem) condition1(finance_10k) xtitle("Value of Finance Sector Contributions") ytitle("Marginal Effect for Democratic Partisanship" "(95% Confidence Interval, one-tailed)")

textable *, fmt(%9.2f)
estimates drop _all
drop marg-lower


